program tomcat;

include <core.vhs>
include <netutil.vhs>
include "apache.vhs";

import core::*;
import core::Pattern::*;
import core::Logging::*;
import core::JobEngine::*;
import netutil::*;
import apache::*;

/* 
Reported date of Apache Tomcat
Tomcat 7: 
	identified/discovered by <reporter> on <reported-date> make public on <date>
	first reported to <name> on <reported-date>
*/

function main() {
	netutil::setWebCacheFolder("apache");
	netutil::setExpiredSecPeriod(60);
	netutil::registerNameResolver(pattern<DataPart>($dataPattern=@'apache\.org/security-(\d+\.html)') 'tomcat-security-' + this[1]);
	
	var filename = download('http://tomcat.apache.org/security.html', SEC_PER_MONTH);
	var file = new CsvFile('tomcat.csv');
	file.writeln('CVE,ReportedDate,AffectVersions,FixedVersion,Title');
	queueJob(ApacheAdvisories, input = new SequenceStream(filename, 4096), 
		outfunc = function(data, file) {
			println("CVE = %s, title=%s, affect to %s, fixed in %s, reported on %s", 
				data.CVE, data.Title, data.AffectVersions, data.FixedVersion, data.ReportedDate);
			file.writeCsvLine([data.CVE, data.ReportedDate, data.AffectVersions, data.FixedVersion, data.Title]);
		}, outfunc_arg = file, minOccur=0, maxOccur=INFINITY);
	waitForQueueDone();
	file.close();
}
